﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;

public class Util
{
    public static string GetRandomStr(int len)
    {
        string src = "0123456789";
        int mode = src.Length;
        Random random = new Random(DateTime.Now.Millisecond);
        StringBuilder str = new StringBuilder(len);
        for (int i = 0; i < len; i++)
        {
            int pos = random.Next() % mode;
            str.Append(src[pos]);
        }
        return str.ToString();
    }

    public static string GetChineseNum(string num)
    {
        string s = string.Empty;
        switch (num)
        {
            case "1":
                s = "一";
                break;
            case "2":
                s = "二";
                break;
            case "3":
                s = "三";
                break;
            case "4":
                s = "四";
                break;
            case "5":
                s = "五";
                break;
            case "6":
                s = "六";
                break;
            case "7":
                s = "七";
                break;
            case "8":
                s = "八";
                break;
            case "9":
                s = "九";
                break;
            case "0":
                s = "零";
                break;
            default:
                break;
        }
        return s;
    }

    /// <summary>
    /// 把列表拆分
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    public static string GetString<T>(IList<T> list)
    {
        StringBuilder sb = new StringBuilder();
        bool first = true;
        foreach (var item in list)
        {
            if (first)
            {
                sb.AppendFormat("{0},", item);
                first = false;
            }
            else
            {
                sb.AppendFormat("{0}.", item);

            }
        }
        return sb.ToString();
    }

    public static void Alert2(string msg, System.Web.UI.Page page)
    {
        string script = string.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>", msg.Replace("\r\n", "\\r\\n"));
        page.ClientScript.RegisterStartupScript(page.GetType(), "alert", script);
    }
}

